from django.test import TestCase

# Create your tests here.
#单元测试
from apitest.models import TestCaseModel


class TestModel(TestCase):

    def test_add(self):
        #方式1
        TestCaseModel.objects.create(name="zhangsan",password="1212")
        #方式2
        TestCaseModel.objects.create(**{"name":'test',"password":'test'})
        #方式3
        model = TestCaseModel(name="test")
        model.save()
        #方式4
        mode2 = TestCaseModel()
        mode2.name="test4"
        mode2.save()

        all = TestCaseModel.objects.all()
        for db in all:
            print(db.__dict__)

        print("换行符----------")
        obj = TestCaseModel.objects.get(pk=1)
        print(obj.__dict__)

        queryset = TestCaseModel.objects.filter(name='test')
        if queryset.exists():
            for db in queryset:
                print(db.password)



